<template>
  <div class="login">
      <el-form label-width="80px" :model="form">
          <div class="title">
              电商后台管理系统
          </div>
          <el-form-item label="用户名">
              <el-input type="text" v-model="form.username" />
          </el-form-item>
          <el-form-item label="密码">
              <el-input type="password" v-model="form.pwd" show-password />
          </el-form-item>
          <el-form-item>
              <el-button type="primary" @click="login">登录</el-button>
          </el-form-item>
      </el-form>
  </div>
</template>

<script>
export default {
    data(){
        return {
            form: {
                username: '',
                pwd: ''
            }
        }
    },
    methods: {
        login(){
            let rel = this.form.username && this.form.pwd
            if(!rel){
                this.$message.warning("请完善账号和密码")
                return
            }

            this.$http({
                path: this.$api.User.login,
                method: 'post',
                params: {
                    username: this.form.username,
                    pwd: this.form.pwd
                }
            }).then(res=>{
                console.log(res);
                this.$message({
                    type: res.code === 200 ? 'success' : 'error',
                    message: res.msg
                })
                if(res.code === 200){
                    localStorage.token = res.token
                    this.$router.push({
                        path: '/'
                    })
                }
            })
        }
    }
}
</script>

<style scoped>
.login{
    height: 100%;
    background-image: linear-gradient(45deg, #78E4CA, #35A6E8);
}
.el-form{
    position: absolute;
    width: 40%;
    height: 360px;
    background-color: #fff;
    left: 50%; 
    top: 40%;
    transform: translate(-50%, -50%); 
    display: flex;
    flex-direction: column;
    justify-content: center;
    box-sizing: border-box;
    padding: 0px 30px;
    border-radius: 10px;
    box-shadow: 3px 4px 5px rgba(0, 0, 0, 0.3);
}
.title{
    text-align: center;
    line-height: 50px;
    margin: 50px 0px;
    font-size: 25px;
    font-weight: bold;
}
</style>